package com.sophialex.health.record.ui.pregnant;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.part.ViewPart;

import com.sophialex.health.record.Messages;
import com.sophialex.health.record.common.draw.DesignUI;
import com.sophialex.health.record.common.draw.UIFormAttachment;
import com.sophialex.health.record.common.utils.CommonUtils;
import com.sophialex.health.record.common.utils.ImageUtil;

/**
 * 产前检查记录
 * <p>Title:Health</p>
 * <p>AntenatalreUI</p>
 * 
 * Alex May 26, 2011 5:14:25 PM create
 * @author <a href='wanghao924@126.com'>Alex</a>
 * QQ: 873987060;
 * @version 1.0
 */
public abstract class AntenatalreUI extends ViewPart {
	public static final String ID = "com.sophialex.health.record.ui.pregnant.AntenatalreUI";

	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());

	   
	protected Label lb_jcsj,lb_yz,lb_xy,lb_tz,lb_gg,lb_fw,lb_tw,lb_txl,lb_xl,lb_xt,lb_sz,lb_ndb,lb_xhdb,lb_bcsc,lb_ggn,lb_qt,lb_gwpd,lb_yxjy,lb_yyrq,lb_jyz;
	
	protected DateTime date_jcsj; //检查时间
	
	protected Text txt_yz;  //孕周
	
	protected Text txt_xy;  //血压
	
	protected Text txt_tz;  //体重
	
	protected Text txt_gg;  //宫高
	
	protected Text txt_fw;  //腹围
	
	protected Text txt_tw; //胎位
	
	protected Text txt_txl; //胎心率 （次/分钟）
	
	protected Combo combo_xl; // 先露

	protected Text txt_xt; // 血糖
	
	protected Text txt_sz; // 水肿
	
	protected Combo combo_ndb; // 尿蛋白

	protected Text txt_xhdb; // 血红蛋白
	
	protected Text txt_bcsc; //B超筛查
	
	protected Combo combo_ggn; // 肝功能
	
	protected Text txt_qt; // 其他
	
	protected Combo combo_gwpd; // 高危评定
	
	protected Text txt_yxjy; // 医学建议
	
	protected DateTime date_yyrq; // 预约日期
	
	protected Text txt_jyz; // 检验者

	public AntenatalreUI() {
	}

	private Composite composite_1;

	protected ToolItem toolItemEdit;

	protected ToolItem toolItemDel;

	protected ToolItem toolItemSave;

	protected ToolItem toolItemCancel;

	protected ToolItem toolItemAdd;

	protected ToolItem toolItemExit;

	protected enum AntenatalreUIState {
		ADD_VIEW, EDIT_VIEW, SHOW_VIEW;
	}

	/**
	 * Create contents of the view part.
	 * 
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);
		container.setLayout(new FormLayout());
		{
			composite_1 = new Composite(container, SWT.NONE);
			composite_1.setLayout(new FillLayout(SWT.HORIZONTAL));
			{
				FormData formData = new FormData();
				formData.height = 50;
				formData.right = new FormAttachment(100);
				formData.top = new FormAttachment(0);
				formData.left = new FormAttachment(0);
				composite_1.setLayoutData(formData);
			}
			{
				ToolBar toolBar = new ToolBar(composite_1, SWT.FLAT | SWT.NONE);
				toolBar.setBackgroundImage(ImageUtil.TBBJ);
				// {
				// toolItemAdd = new ToolItem(toolBar, SWT.NONE);
				//					toolItemAdd.setText(Messages.getString("RecordUI.0")); //$NON-NLS-1$
				// toolItemAdd.setImage(ImageUtil.add);
				// toolItemAdd.addSelectionListener(new SelectionAdapter() {
				// @Override
				// public void widgetSelected(SelectionEvent e) {
				// doAdd();
				// }
				// });
				// }
				{
					toolItemEdit = new ToolItem(toolBar, SWT.NONE);
					toolItemEdit.setText(Messages.getString("RecordUI.1")); //$NON-NLS-1$
					toolItemEdit.setImage(ImageUtil.edit);
					toolItemEdit.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doEdit();
						}
					});
				}
				{
					toolItemDel = new ToolItem(toolBar, SWT.NONE);
					toolItemDel.setText(Messages.getString("RecordUI.2")); //$NON-NLS-1$
					toolItemDel.setImage(ImageUtil.delete);
					toolItemDel.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doDel();
						}
					});
				}
				{
					@SuppressWarnings("unused")
					ToolItem toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
				}
				{
					toolItemSave = new ToolItem(toolBar, SWT.NONE);
					toolItemSave.setText(Messages.getString("RecordUI.3")); //$NON-NLS-1$
					toolItemSave.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doSave();
						}
					});
					toolItemSave.setImage(ImageUtil.save);
				}

				{
					toolItemCancel = new ToolItem(toolBar, SWT.NONE);
					toolItemCancel.setText(Messages.getString("RecordUI.4")); //$NON-NLS-1$
					toolItemCancel.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doCancel();
						}
					});
					toolItemCancel.setImage(ImageUtil.cancel);
				}
				{
					toolItemExit = new ToolItem(toolBar, SWT.NONE);
					toolItemExit.setText(Messages.getString("RecordUI.6")); //$NON-NLS-1$
					toolItemExit.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doExit();
						}
					});
					toolItemExit.setImage(ImageUtil.exit);
				}
				/*
				 * { ToolItem toolItem = new ToolItem(toolBar, SWT.NONE);
				 * toolItem.setText(Messages.getString("RecordUI.5"));
				 * //$NON-NLS-1$ toolItem.setImage(ImageUtil.print);
				 * toolItem.addSelectionListener(new SelectionAdapter() {
				 * 
				 * @Override public void widgetSelected(SelectionEvent e) {
				 * doPrint(); } }); }
				 */
			}
		}

		{
			Composite composite = new Composite(container, SWT.NONE);
			{
				FormData formData = new FormData();
				formData.top = new FormAttachment(composite_1, 0);
				formData.bottom = new FormAttachment(100, -4);
				formData.right = new FormAttachment(composite_1, 0, SWT.RIGHT);
				formData.left = new FormAttachment(composite_1, 0, SWT.LEFT);
				composite.setLayout(new FillLayout(SWT.FILL));
				composite.setLayoutData(formData);

			}
			drawUI(composite);
		}
		initCombo();
		createActions();
		initializeToolBar();
		initializeMenu();

		this.setPartName(Messages.getString("AntenatalreView.Title")); //$NON-NLS-1$

	}

	// 绘制界面
	private void drawUI(Composite parent) {

		ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		toolkit.adapt(scrolledComposite);
		toolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);

		ScrolledForm scrldfrmNewScrolledform = toolkit.createScrolledForm(scrolledComposite);
		toolkit.paintBordersFor(scrldfrmNewScrolledform);
		scrldfrmNewScrolledform.setText("   姓名：张三             个人档案编号：152877552142211");
		scrldfrmNewScrolledform.getBody().setLayout(new FormLayout());
		Label horLine =  new Label(scrldfrmNewScrolledform.getBody(), SWT.SEPARATOR | SWT.HORIZONTAL);
		FormData fd_horLine = new FormData();
		fd_horLine.top = new FormAttachment(0, 10);
		fd_horLine.left = new FormAttachment(2, 0);
		fd_horLine.right = new FormAttachment(100,-10);
		horLine.setLayoutData(fd_horLine);
		toolkit.adapt(horLine, true, true);
		
		//检查时间
		{
			lb_jcsj = toolkit.createLabel(scrldfrmNewScrolledform.getBody(), "检查时间：", SWT.NONE);
			FormData fd_label = new FormData();
			fd_label.top = new FormAttachment(0, 35);
			fd_label.left = new FormAttachment(2, 0);
			lb_jcsj.setLayoutData(fd_label);
			
			date_jcsj = new DateTime(scrldfrmNewScrolledform.getBody(), SWT.BORDER | SWT.DROP_DOWN);
			FormData fd_txtNewText = new FormData();
			fd_txtNewText.right = new FormAttachment(lb_jcsj, 166, SWT.RIGHT);
			fd_txtNewText.top = new FormAttachment(lb_jcsj,-8,SWT.TOP);
			fd_txtNewText.bottom = new FormAttachment(lb_jcsj,0,SWT.BOTTOM);
			fd_txtNewText.left = new FormAttachment(lb_jcsj, 6);
			date_jcsj.setLayoutData(fd_txtNewText);
			toolkit.adapt(date_jcsj, true, true);
		}
		
		// 检查项目
		UIFormAttachment jcxmsectionUIAttachment = UIFormAttachment.getDefault(lb_jcsj,12,0,true);
		Section jcxmSection = DesignUI.drawSection(toolkit, scrldfrmNewScrolledform, jcxmsectionUIAttachment, "检查项目",false);
		Composite composite_jcxm = DesignUI.drawSectionComposite(toolkit, jcxmSection);
		List<Control[]> jcxmControlList = new ArrayList<Control[]>();
		//孕周
		{
			lb_yz = toolkit.createLabel(composite_jcxm, "                    孕周：", SWT.NONE);
			txt_yz = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = {lb_yz,txt_yz};
			jcxmControlList.add(controls);
		}
		//血压
		{
			lb_xy = toolkit.createLabel(composite_jcxm, "血压（mmHg）：", SWT.NONE);
			txt_xy = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = {lb_xy,txt_xy};
			jcxmControlList.add(controls);
		}
		//体重
		{
			lb_tz = toolkit.createLabel(composite_jcxm, "   体重（kg）：", SWT.NONE);
			txt_tz = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = {lb_tz,txt_tz};
			jcxmControlList.add(controls);
		}
		//宫高
		{
			lb_gg = toolkit.createLabel(composite_jcxm, "宫高（cm）：", SWT.NONE);
			txt_gg = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = {lb_gg,txt_gg};
			jcxmControlList.add(controls);
		}
		//腹围
		{
			lb_fw = toolkit.createLabel(composite_jcxm, "腹围（cm）：", SWT.NONE);
			txt_fw = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = {lb_fw,txt_fw};
			jcxmControlList.add(controls);
		}
		//胎位
		{
			lb_tw = toolkit.createLabel(composite_jcxm, "胎位：", SWT.NONE);
			txt_tw = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = {lb_tw,txt_tw};
			jcxmControlList.add(controls);
		}
		//胎心率
		{
			lb_txl = toolkit.createLabel(composite_jcxm, "胎心率（次/分钟）：", SWT.NONE);
			txt_txl = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = {lb_txl,txt_txl};
			jcxmControlList.add(controls);
		}
		// 先露
		{
			lb_xl = toolkit.createLabel(composite_jcxm, "先露：", SWT.NONE);
			combo_xl = new Combo(composite_jcxm, SWT.READ_ONLY);
			Control[] controls = { lb_xl, combo_xl };
			jcxmControlList.add(controls);
		}		
		// 血糖
		{
			lb_xt = toolkit.createLabel(composite_jcxm, "血糖（mmol/L）：", SWT.NONE);
			txt_xt = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = { lb_xt, txt_xt };
			jcxmControlList.add(controls);
		}
		// 水肿
		{
			lb_sz = toolkit.createLabel(composite_jcxm, "水肿：", SWT.NONE);
			txt_sz = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = { lb_sz, txt_sz };
			jcxmControlList.add(controls);
		}
		// 尿蛋白
		{
			lb_ndb = toolkit.createLabel(composite_jcxm, "尿蛋白：", SWT.NONE);
			combo_ndb = new Combo(composite_jcxm, SWT.READ_ONLY);
			Control[] controls = { lb_ndb, combo_ndb };
			jcxmControlList.add(controls);
		}
		// 血红蛋白(g/L)
		{
			lb_xhdb = toolkit.createLabel(composite_jcxm, "血红蛋白(g/L)：", SWT.NONE);
			txt_xhdb = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = { lb_xhdb, txt_xhdb };
			jcxmControlList.add(controls);
		}
		//B超筛查
		{
			lb_bcsc = toolkit.createLabel(composite_jcxm, "B超筛查：", SWT.NONE);
			txt_bcsc = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = { lb_bcsc, txt_bcsc };
			jcxmControlList.add(controls);
		}
		// 肝功能
		{
			lb_ggn = toolkit.createLabel(composite_jcxm, "肝功能：", SWT.NONE);
			combo_ggn = new Combo(composite_jcxm, SWT.READ_ONLY);
			Control[] controls = { lb_ggn, combo_ggn };
			jcxmControlList.add(controls);
		}
		//高危评定
		{
			lb_gwpd = toolkit.createLabel(composite_jcxm, "高危评定：", SWT.NONE);
			combo_gwpd = new Combo(composite_jcxm, SWT.READ_ONLY);
			Control[] controls = { lb_gwpd, combo_gwpd };
			jcxmControlList.add(controls);
		}
		//其他
		{
			lb_qt = toolkit.createLabel(composite_jcxm, "其他：", SWT.NONE);
			txt_qt = toolkit.createText(composite_jcxm, "", SWT.NONE);
			Control[] controls = { lb_qt, txt_qt };
			jcxmControlList.add(controls);
		}
		DesignUI.defaultWidth = 146;
		DesignUI.drawSecionContent(composite_jcxm,jcxmControlList,4,true,null);
		DesignUI.reset();
		
		// 医学建议
		{
			lb_yxjy = toolkit.createLabel(composite_jcxm, "医学建议：", SWT.NONE);
			FormData fd_cl = new FormData();
			fd_cl.top = new FormAttachment(lb_bcsc, 40, SWT.TOP);
			fd_cl.right = new FormAttachment(lb_bcsc, 0, SWT.RIGHT);
			lb_yxjy.setLayoutData(fd_cl);

			txt_yxjy = toolkit.createText(composite_jcxm, "", SWT.WRAP | SWT.MULTI | SWT.V_SCROLL);
			FormData fd_txt_cl = new FormData();
			fd_txt_cl.right = new FormAttachment(combo_ggn, 0, SWT.RIGHT);
			fd_txt_cl.top = new FormAttachment(lb_yxjy, 0, SWT.TOP);
			fd_txt_cl.bottom = new FormAttachment(lb_yxjy, 60, SWT.BOTTOM);
			fd_txt_cl.left = new FormAttachment(lb_yxjy, 6);
			txt_yxjy.setLayoutData(fd_txt_cl);
		}
		// 预约日期
		{
			lb_yyrq = toolkit.createLabel(composite_jcxm, "预约日期：", SWT.NONE);
			FormData fd_yyrq = new FormData();
			fd_yyrq.top = new FormAttachment(lb_yxjy, 0, SWT.TOP);
			fd_yyrq.right = new FormAttachment(lb_gwpd, 0, SWT.RIGHT);
			lb_yyrq.setLayoutData(fd_yyrq);
			
			date_yyrq = new DateTime(composite_jcxm, SWT.BORDER | SWT.DROP_DOWN);
			FormData fd_txt_cl = new FormData();
			fd_txt_cl.right = new FormAttachment(lb_yyrq, 146, SWT.RIGHT);
			fd_txt_cl.top = new FormAttachment(lb_yyrq, -8, SWT.TOP);
			fd_txt_cl.bottom = new FormAttachment(lb_yyrq,0,SWT.BOTTOM);
			fd_txt_cl.left = new FormAttachment(lb_yyrq, 6);
			date_yyrq.setLayoutData(fd_txt_cl);
		}
		// 检查者签名
		{
			lb_jyz = toolkit.createLabel(composite_jcxm, "检查者签名：", SWT.NONE);
			FormData fd_pgr = new FormData();
			fd_pgr.top = new FormAttachment(lb_yyrq, 0, SWT.TOP);
			fd_pgr.right = new FormAttachment(lb_qt, 0, SWT.RIGHT);
			lb_jyz.setLayoutData(fd_pgr);
			txt_jyz = toolkit.createText(composite_jcxm, "", SWT.NONE);
			FormData fd_txt_pgr = new FormData();
			fd_txt_pgr.right = new FormAttachment(txt_qt, 0, SWT.RIGHT);
			fd_txt_pgr.top = new FormAttachment(lb_jyz, -8, SWT.TOP);
			fd_txt_pgr.bottom = new FormAttachment(lb_jyz, 0, SWT.BOTTOM);
			fd_txt_pgr.left = new FormAttachment(lb_jyz, 6);
			txt_jyz.setLayoutData(fd_txt_pgr);
		}
		
		
		scrolledComposite.setContent(scrldfrmNewScrolledform);
		scrolledComposite.setMinSize(scrldfrmNewScrolledform.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	}

	protected void doExport() {

	}

	protected void doExit() {
		getViewSite().getPage().hideView(this);
	}

	protected abstract void doCancel();

	protected abstract void doSave();

	protected abstract void doDel();

	protected abstract void doEdit();

	protected abstract void doAdd();

	protected abstract void doPrint();

	/**
	 * Create the actions.
	 */
	private void createActions() {

	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		@SuppressWarnings("unused")
		IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		@SuppressWarnings("unused")
		IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
	}

	public void initCombo() {

		CommonUtils.initCombo(combo_ggn, "ZCYC");
		CommonUtils.initCombo(combo_xl, "XIANL");
		CommonUtils.initCombo(combo_ndb, "NDB2");
		CommonUtils.initCombo(combo_gwpd, "GWPD");
	}

}
